<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>查看二维码</title>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<script type="text/javascript">
	//js图片另存为方法
	function downLoadImage(imagePathURL){
		if(document.all._SAVEASIMAGE_TEMP_FRAME.src!=imagePathURL){
			//图片地址发生变化，加载图片
			document.all._SAVEASIMAGE_TEMP_FRAME.src = imagePathURL;
		}else{
			//图片地址没有变化，直接另存为
			_doSaveAsImage();
		}
	}
	//js图片另存为方法
	function _doSaveAsImage() {
		if (document.all._SAVEASIMAGE_TEMP_FRAME.src != "about:blank") {
			if (!!window.ActiveXObject || "ActiveXObject" in window) {
				document.frames["_SAVEASIMAGE_TEMP_FRAME"].document.execCommand("SaveAs");
			} else {
				saveAs(document.all._SAVEASIMAGE_TEMP_FRAME.src, "${classId}.png");
			}
		}
	}

	function saveAs(Url, filename) {
		var blob = new Blob([ '' ], {type : 'application/octet-stream'});
		var url = webkitURL.createObjectURL(blob);
		var a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
		a.href = Url;
		a.download = filename;
		var e = document.createEvent('MouseEvents');
		e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false,false, false, false, 0, null);
		a.dispatchEvent(e);
		webkitURL.revokeObjectURL(url);
	}

	function base64_encode(str) {
		var c1, c2, c3;
		var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
		var i = 0, len = str.length, string = '';
		while (i < len) {
			c1 = str.charCodeAt(i++) & 0xff;
			if (i == len) {
				string += base64EncodeChars.charAt(c1 >> 2);
				string += base64EncodeChars.charAt((c1 & 0x3) << 4);
				string += "==";
				break;
			}
			c2 = str.charCodeAt(i++);
			if (i == len) {
				string += base64EncodeChars.charAt(c1 >> 2);
				string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
				string += base64EncodeChars.charAt((c2 & 0xF) << 2);
				string += "=";
				break;
			}
			c3 = str.charCodeAt(i++);
			string += base64EncodeChars.charAt(c1 >> 2);
			string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
			string += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
			string += base64EncodeChars.charAt(c3 & 0x3F)
		}
		return string
	}
</script>
<style type="text/css">
	.pageView{
		padding:0;
		margin:0;
	}
</style>
</head>
<body class="pageView">
<table width="400" border="0" cellspacing="0" cellpadding="0" style="margin:10px auto 0 auto;">
  <tr>
    <td id="className" name="className" align="center" valign="middle" style="font-size:20px;"><c:out value="${className}"></c:out></td>
  </tr>
  <tr>
    <td align="center" valign="middle" style="padding:10px;">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	        <tr>
	          <td align="center">
	          	<div  id="div1">
	          		<img id="classCode" name="classCode" src="<%=basePath%>erweima/classErweima/${classId}.png" width="300" height="300" style="padding:10px; border:1px #ccc solid;" />
	          		<br/>
	          		<input type="button" value="下载" style="cursor: hand" onclick="downLoadImage(document.getElementById('classCode').src);" />
	          	</div>
	          	<script>
	          		var img=document.getElementById('classCode');
	          		img.onerror=function(){
	          			document.getElementById('div1').innerHTML='本班没有生成二维码';
	          		};
	          	</script>
	          </td>
	        </tr>
	       <!--  <tr>
	          <td align="center" style="padding:10px; display:none1;">
	            
	          </td>
	        </tr> -->
	        <tr>
	          <td align="center" style="padding:10px; display:none1;">
	            <input type="text" value="${questionnaireUrl}" style="width:400px"></input>
	          </td>
	        </tr>
       </table>
    </td>
  </tr>
</table>
<!-- 图片另存为的隐藏ifrme begin -->
<iframe onload="_doSaveAsImage()" style="display:none;" id="_SAVEASIMAGE_TEMP_FRAME" name="_SAVEASIMAGE_TEMP_FRAME" width="0" height="0" src="about:blank">	</iframe>
</body>
</html>
